from rest_framework import serializers
from rest_framework.response import Response 
from app01 import models
class StudentSerializer_list(serializers.ModelSerializer):
    classroom_name = serializers.SerializerMethodField()

    class Meta:
        model = models.Student
        fields = ['username', 'classroom_name', 'portrait_url', 'student_id', 'gender']

    def get_classroom_name(self, instance):
        return instance.classroom.class_name if instance.classroom else None

    def to_representation(self, instance):
        representation = super().to_representation(instance)
        representation['status'] = True  # 根据需要设置这个字段的值
        return representation    
class StudentSerializer_show(serializers.ModelSerializer):  
    classroom_name = serializers.SerializerMethodField()
    class Meta:  
        model = models.Student  
        fields = ['username', 'classroom_name', 'portrait_url', 'student_id', 'gender','phone_number','birthday','psychological_info','emotion_and_behavior','student_relations','head_teacher']
    def get_classroom_name(self, instance):
        return instance.classroom.class_name if instance.classroom else None
    def to_representation(self, instance):
        representation = super().to_representation(instance)
        representation['status'] = True  # 你可以根据需要设置这个字段的值
        return representation   
class StudentBehaviorSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Student
        fields = ['id', 'emotion_and_behavior']  # 可以根据实际情况调整需要包含的字段